package parser

import (
	"learngo/crawler/engine"
	"regexp"
)

const cityRegex = `<a href="(http://www.zhenai.com/zhenghun/\w+)"[^>]*>([^<]+)</a>`

func ParseCityList(contents []byte) engine.ParseResult {
	rs := engine.ParseResult{}

	reg := regexp.MustCompile(cityRegex)
	match := reg.FindAllSubmatch(contents, -1)

	// match type : [][] []byte->string
	//limit := 10
	for _, m := range match {
		//rs.Items = append(rs.Items, "City " + string(m[2])) // 城市名称
		// 城市对应的请求链接
		rs.Requests = append(rs.Requests, engine.Request{
			Url:       string(m[1]),
			ParseFunc: ParseCity,
		})

		//limit --
		//if limit <= 0 {
		//	break
		//}
	}
	return rs
}
